<template>
  <view>
    <cu-custom bgColor="bg-gradual-green" :isBack="true">
      <block slot="backText">返回</block>
      <block slot="content">添加体适能评估</block>
    </cu-custom>
    <view class="all_list">
      <view class="items u-f-ajc" v-for="(item, index) in list" :key="index" @click="goPage(item.path)">
        <image src="../../static/37.png" />
        <view v-if="!item.isShow" class="relative" style="font-size: 36rpx;">{{item.title}}</view>
        <view v-else class="relative t-a-c">
          <view class="cuIcon-roundcheck"></view>
          <view style="font-size: 24rpx;">{{item.title}}</view>
        </view>
      </view>
    </view>
    <button type="default" class="bottom-btn u-f-ajc" @click="submit">完成</button>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        list: [{
            title: '平衡测试',
            isShow: false,
            path: '/pagesA/Physical_fitness_assessment/children/parallel_test',
          },
          {
            title: '心肺耐力',
            isShow: false,
            path: '/pagesA/Physical_fitness_assessment/children/Cardiopulmonary_endurance',
          },
          {
            title: '柔韧性',
            isShow: false,
            path: '/pagesA/Physical_fitness_assessment/children/suppleness',
          },
          {
            title: '肌肉力量',
            isShow: false,
            path: '/pagesA/Physical_fitness_assessment/children/muscular_strength',
          },
          {
            title: '肌肉耐力',
            isShow: false,
            path: '/pagesA/Physical_fitness_assessment/children/muscular_endurance',
          },
        ],
        fmsDetails2: {},
      }
    },
    onLoad() {
      this.fmsDetails2 = uni.getStorageSync('fmsDetails2')
      let computs = (items, names) => {
        if (this.fmsDetails2.hasOwnProperty(items)) {
          let index = this.list.findIndex(item => item.title == names)
          this.list[index].isShow = true
        }
      }
      computs('list1', '平衡测试')
      computs('list2', '心肺耐力')
      computs('list3', '柔韧性')
      computs('list4', '肌肉力量')
      computs('list5', '肌肉耐力')
    },
    methods: {
      goPage(url) {
        console.log(url)
        uni.redirectTo({
          url
        })
      },
      async submit() {
        if (this.list.every(item => item.isShow)) {
          let data = {
            "bId": 1,
            "balanceTest": {
              left: this.fmsDetails2.list1[0].input,
              right: this.fmsDetails2.list1[1].input,
            },
            "bpm": this.fmsDetails2.list2.input,
            "flexibility": this.fmsDetails2.list3,
            "gymId": 0,
            "memberId": uni.getStorageSync('phyUser').userId,
            "muscleEndurance": this.fmsDetails2.list5.input,
            "muscleStrength": this.fmsDetails2.list4.input,
            "userId": uni.getStorageSync('openid'),
            "userName": uni.getStorageSync('userName')
          }
          console.log(data)
          let res = await this.$myRuquest({
            url: '/coach/body/addPhysicalAbility',
            method: "POST",
            header: {
              'Content-Type': 'application/json',
            },
          })
          console.log('查看提交', res)
          return
          uni.redirectTo({
            url: '/pagesA/Physical_fitness_assessment/Project_details',
          });

        } else {
          return this.$showToast('请完成全部测试~', 'none')
        }
      },
    }
  }
</script>

<style lang="scss">
  .all_list {
    padding: 20rpx 30rpx;
  }

  .items {
    width: 100%;
    height: 150rpx;
    border-radius: 20rpx;
    background-color: $uni-color-zhuti;
    margin-bottom: 30rpx;
    overflow: hidden;
    position: relative;
    color: #FFFFFF;

    image {
      position: absolute;
      left: 0;
      right: 0;
      top: 0;
      width: 100%;
      height: 100%;
      z-index: 0;
    }
  }

  .cuIcon-roundcheck {
    font-size: 60rpx;
    color: $uni-color-zhuti;
  }

  .bottom-btn {
    width: 100%;
    height: 100rpx;
    background-color: $uni-color-zhuti !important;
    color: #FFFFFF !important;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 99;
  }
</style>
